<!DOCTYPE html>
<html>
<!--
  * Please see the included README.md file for license terms and conditions.
  -->
<head>
    <title>Blank App Designer Cordova Web App Project Template</title>
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8">
    <!-- <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1"> -->
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=no">
    <!-- <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, minimum-scale=1, maximum-scale=2"> -->
    <style>
    /* following three (cascaded) are equivalent to above three meta viewport statements */
    /* see http://www.quirksmode.org/blog/archives/2014/05/html5_dev_conf.html */
    /* see http://dev.w3.org/csswg/css-device-adapt/ */
        @-ms-viewport { width: 100vw ; min-zoom: 100% ; zoom: 100% ; }          @viewport { width: 100vw ; min-zoom: 100% zoom: 100% ; }
        @-ms-viewport { user-zoom: fixed ; min-zoom: 100% ; }                   @viewport { user-zoom: fixed ; min-zoom: 100% ; }
        /*@-ms-viewport { user-zoom: zoom ; min-zoom: 100% ; max-zoom: 200% ; }   @viewport { user-zoom: zoom ; min-zoom: 100% ; max-zoom: 200% ; }*/
		.btnL
		{
			border-top-style:none;
			border-right-style: none;
			border-bottom-style: none;
			border-left-style: none;
			background:none;
			width:100%;
			height:100%;
			color:white;
		}

		td
		{
			height:40px;
		}


		
    </style>

    <link rel="stylesheet" href="css/app.css">
    <script src="cordova.js" id="xdkJScordova_"></script>
    <script src="js/app.js"></script>           
    <script src="js/init-app.js"></script>      <!-- for your init code, see README and file comments for details -->
    <script src="xdk/init-dev.js"></script>
    <script src="intelxdk.js"></script>
    <script type="text/javascript">
        var onDeviceReady=function(){
            intel.xdk.device.hideSplashScreen();
        };
        document.addEventListener("inter.xdk.device.ready",onDeviceReady,false);
    </script>
	<!--
	<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
	<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
	<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
	-->
	<link rel="stylesheet" href="jquery.mobile-1.3.2.min.css">
    <script src="jquery-latest.js"></script>
	<script src="jquery.mobile-1.3.2.min.js"></script>
	
    <script type="text/javascript">
	
	//加载学院列表
     $(document).on('pageshow','#CollegaList',function(){
        $.ajax({
            url:'http://localhost:3050/api/学院',
            type:'GET',
            dataType:'json',
            jsonp:'callback',
            jsonpCallback:'?',
            timeout:1000,
            async:false,
            success:function(json){
				$('#学院-list').html("");
                sessionStorage.setItem('Collega_Id',0);
                $.each(json,function(i,row){
                    $('#学院-list').append('<li  ><a href="#CollegaDetail"  data-transition="slide" onClick="sessionStorage.setItem(\'Collega_Id\','+row.Id+');"><h2>' + row.名称+ '</h2></a></li>');
               // $('#学院-list').append('<li><a href="" data-id="'+row.id+'"><h2>'+row.名称+'</h2></a></li>');
                });
				$('#学院-list').listview('refresh');
            },
            error:function(request,error){
                alert('加载错误:'+error);
            }
        });
    });    

	//加载学院详情页
     $(document).on('pageshow','#CollegaDetail',function(){
        if(sessionStorage.getItem('Collega_Id')==0)  //判断是否为修改学院，否则清空标签内容以便新建学院
        {
            $("#collegaName").val("");	//学院名
            $("#collegaAddress").val("");	//学院地址
			$('#GuideCollega').hide();	//隐藏 非相关功能区
        }
        else
		 {
			 $('#GuideCollega').show();		//显示 修改学院 相关的功能区
			 $.ajax({
					url:'http://localhost:3050/api/学院/'+sessionStorage.getItem('Collega_Id'),
					type:'GET',
					dataType:'json',
					jsonp:'callback',
					jsonpCallback:'?',
					timeout:1000,
					async:false,
					success:function(json){
						$("#collegaName").val(json["名称"]);	//将原数据读入
						$("#collegaAddress").val(json["地址"]);	 
						//$("#collegaName").textinput("refresh");
						//$("#collegaAddress").textinput('refresh');
					},
					error:function(request,error){
						alert('加载错误:'+error);
					}
				});
		}
    });
	
	//加载系部面板
	 $(document).on("panelbeforeopen",'#DepartmentPanel',function(){
		$.ajax({
            url:'http://localhost:3050/api/学院/'+sessionStorage.getItem('Collega_Id')+'/系部',
            type:'GET',
            dataType:'json',
            jsonp:'callback',
            jsonpCallback:'?',
            timeout:1000,
            async:false,
            success:function(json){
				$('#系部-list').html("");
                sessionStorage.setItem('Department_Id',0);
                $.each(json,function(i,row){
                    $('#系部-list').append('<li  ><a href="#classListPage" data-transition="slide" onClick="sessionStorage.setItem(\'Department_Id\','+row.Id+');"><h2>' + row.系名+ '</h2></a></li>');
                });
				$('#系部-list').listview('refresh');
            },
            error:function(request,error){
                alert('加载错误:'+error);
            }
        });
	 });
	

	//加载班级列表
	$(document).on('pageshow','#classListPage',function(){
		$.ajax({
			url:'http://localhost:3050/api/系部/'+sessionStorage.getItem('Department_Id')+'/班级',
			type: 'GET',
			dataType:'json',
			jsonp:'callback',
			jsonpCallback:'?',
			timeout:1000,
			async:false,
			success:function(json){
				$('#班级-list').html("");	//清空列表原有的值
				$.each(json,function(i,row){	//遍历并添加获取到的班级 
					$('#班级-list').append('<li><a href="#" onClick="sessionStorage.setItem(\'class_Id\','+row.Id+');setClass();"><h2>'+row.入学年份+row.名称+'</h2></a></li>');
				});
				$('#班级-list').listview('refresh');	//刷新班级列表
			},
			error:function(request,error){
				alert('加载错误：'+error);
			}
		});
	});

	//加载个人信息
	$(document).on('panelbeforeopen','#UserInfo',function(){
		$.ajax({
			url:'http://localhost:3050/api/用户/'+localStorage.getItem('loginId')+'/个人信息',
			type: 'GET',
			dataType:'json',
			jsonp:'callback',
			jsonpCallback:'?',
			timeout:1000,
			async:false,
			success:function(json){
				var temp=json.split('#');
				document.getElementById("user_nc").innerHTML="昵称："+temp[0];
				document.getElementById("user_xy").innerHTML="学院："+temp[1];
				document.getElementById("user_xb").innerHTML="系部："+temp[2];
				document.getElementById("user_bj").innerHTML="班级："+temp[3];
			},
			error:function(request,error){
				alert('加载错误：'+error);
			}
		});
	});

	//加载课程列表
	$(document).on('pageshow','#CourseList',function(){
		$.ajax({
			url:'http://localhost:3050/api/课程课表/课程',
			type: 'GET',
			dataType:'json',
			jsonp:'callback',
			jsonpCallback:'?',
			timeout:1000,
			async:false,
			success:function(json){
				$('#courseList').html("");	//清空列表原有的值
				$.each(json,function(i,row){	//添加
					$('#courseList').append('<li ><a  href="#"><h2>'+row.课程名+'</h2></a></li>');
				});
				$('#courseList').listview('refresh');	//刷新
			},
			error:function(request,error){
				alert('加载错误：'+error);
			}
		});
		
	});

	//创建课程表周次下拉框
	$(document).on('pageshow','#CourseTable',function(){
		var cw=document.getElementById('currentWeek');;	
		for(var i=1;i<=20;i++){
			cw.add(new Option("第"+i+"周",i));
		}
		loadCourses(-1);
		document.getElementById('courseTable_name').innerHTML=localStorage.getItem("loginName");
	});


	//课程详情页
	$(document).on('pageshow','#CourseInfo',function(){
		$.ajax({
			url:'http://localhost:3050/api/课程/'+sessionStorage.getItem('curent_C')+'/课程详情',
			type: 'GET',
			dataType:'json',
			jsonp:'callback',
			jsonpCallback:'?',
			timeout:1000,
			async:false,
			success:function(json){
				document.getElementById("CourseInfo_kcm").innerHTML=json.课程名;
				document.getElementById("CourseInfo_dd").innerHTML="地点："+json.地点;
				//document.getElementById("CourseInfo_sj").innerHTML=json.地点;
				document.getElementById("CourseInfo_jc").innerHTML="节次："+json.节次;
				document.getElementById("CourseInfo_js").innerHTML="教师："+json.学期;
				document.getElementById("CourseInfo_zc").innerHTML="周次："+json.周次;
				document.getElementById("CourseInfo_kclx").innerHTML="课程类别："+json.课程类别;
				//alert(json.教师.姓名);
				//$('#teacher').listview('refresh');	//刷新
			},
			error:function(request,error){
				alert('加载错误：'+error);
			}
		});
	});

	//加载添加课程页相关
	$(document).on('pageshow','#NewCourse',function(){
		$.ajax({
			url:'http://localhost:3050/api/班级/'+localStorage.getItem('class_Id')+'/教师',
			type: 'GET',
			dataType:'json',
			jsonp:'callback',
			jsonpCallback:'?',
			timeout:1000,
			async:false,
			success:function(json){
				$('#teacher').html("");	//清空列表原有的值
				$.each(json,function(i,row){	//添加
					$('#teacher').append('<option value='+row.Id+' >'+row.姓名+'</option>');
				});
			},
			error:function(request,error){
				alert('加载错误：'+error);
			}
		});
	});
	
    //添加一个学院
    function add(){
		if($("#collegaName").val()=="" && $("#collegaAddress").val()=="")	//判断内容是否合法
			alert("内容不能为空！");
		
		else
		{	//将新学院数据添入表格
			var json=JSON.stringify({名称:$("#collegaName").val(),地址:$("#collegaAddress").val()});
			$.ajax({
				url:'http://localhost:3050/api/学院',
				cache:false,
				type:'POST',
				contentType: 'application/json; charset=utf-8',
				data:json,
				statusCode:{
					204: function(data){
						$.mobile.changePage('#CollegaList',{reloadPage : false });                
					}                          
				}
			});
		}
	}

	//修改学院信息
    function modify(){
        var json=JSON.stringify({Id:sessionStorage.getItem("Collega_Id"),名称:$("#collegaName").val(),地址:$("#collegaAddress").val()});
        $.ajax({
            url:'http://localhost:3050/api/学院/'+sessionStorage.getItem('Collega_Id'),
            cache:false,
            type:'PUT',
            contentType:'application/json;charset=utf-8',
            data:json,
            statusCode:{
                204:function(data){
                    $.mobile.changePage('#CollegaList',{reloadPage : false});	//修改成功跳转至学院列表页
                }
            }
        });
    }

	//学院操作处理 判断此页面是作为 添加或者修改来处理
    function doSubmit(){	
        if(sessionStorage.getItem('Collega_Id')==0)
			add();
        else
        {
            modify();
        }
    }

	//删除学院
    function doDelete(){
        $.ajax({
            url:'http://localhost:3050/api/学院/'+sessionStorage.getItem('Collega_Id'),
            cache:false,
            type:'DELETE',
            contentType:'application/json;charset=utf-8',
            statusCode:{
                204:function(data){
                    $.mobile.changePage('#CollegaList',{reloadPage : false});
                }
            }
        });
    }

	//登录
    function login(id,pwd){
        var json=JSON.stringify({昵称:id.val(),密码:pwd.val()});
        //alert(json);
        localStorage.removeItem("loginId");		//移除本地存储数据
        localStorage.removeItem("loginPwd");	
        $.ajax({
            url:'http://localhost:3050/api/user/login',
            cache: false,
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            data:json,
            statusCode:{
                200:function(data){
                    if(data["Id"]!=0){	//用户通过验证
                        localStorage.setItem("loginId",data["Id"]);		//将用户基本数据本地存储
                        localStorage.setItem("loginPwd",data["密码"]);
						localStorage.setItem("loginName",data["昵称"]);
						loginHandler();
						
                    }else{
                        alert("登录失败！");
                    }
                },
                error:function(request,error){
                    alert('Server Error:'+error);
                }
            }
            
        });
        
    }   
	
	//登陆处理(判断是否为新用户)
	function loginHandler()
	{
		//alert("aa");
		$.ajax({
			url:'http://localhost:3050/api/user/'+localStorage.getItem("loginId")+'/验证',
			type: 'POST',
			dataType:'json',
			jsonp:'callback',
			jsonpCallback:'?',
			timeout:1000,
			async:false,
			success:function(json){
				if(json!=0){	//用户已设置过班级
					localStorage.setItem('class_Id',json);
					$.mobile.changePage('#CourseTable',{reloadPage : false });	//用户中心 
                }else{
                    $.mobile.changePage('#CollegaList',{reloadPage : false });	//向导页  
                }
			},
			error:function(request,error){
				alert('加载错误：'+error);
			}
		});
	}

	//注册
    function register(){
		var json=JSON.stringify({昵称:$("#tPhone").val(),手机号码:$("#tPhone").val(),密码:$("#tregPwd").val()});
		$.ajax({
			url:'http://localhost:3050/api/用户/注册',
			cache:false,
			type:'POST',
			contentType: 'application/json; charset=utf-8',
			data:json,
			statusCode:{
				200: function(data){	
					if(!data)
					{alert("手机号码已经被注册！");
						 document.getElementById("tPhone").value="";
					}
					else
					{
						alert('注册成功!');
						login($('#tPhone'),$('#tregPwd'));	//注册成功 即直接登陆！
					}
				}                          
			}
		});
    }

	//注册处理 验证用户相关输入是否合法
	function handles()
	{
		var tPhone = document.getElementById("tPhone").value;	//手机号
		var tPwd = document.getElementById("tregPwd").value;	//密码
		if( tPhone=='' || tPwd=='')
			alert('内容不能为空！');
		else
			register();
			
	}

	//设置当前用户的班级
	function setClass()
	{
		$.ajax({
			url:'http://localhost:3050/api/user/'+localStorage.getItem('loginId')+'/class/'+sessionStorage.getItem('class_Id'),
			cache: false,
			type: 'POST',
			statusCode:{
				200 /*Update*/:function(data){
					if(data!='0')	
					{
						localStorage.setItem('class_Id',sessionStorage.getItem('class_Id'));
						if(event.returnValue = confirm("设置成功！立即跳转到课程表页！"))
							$.mobile.changePage('#CourseTable',{reloadPage : false }); 
					}
					else
					{
						alert('设置失败!');
					}
				}
			}
		});
	}

	 //添加一个班级
	function addClass(){
		var json=JSON.stringify({入学年份:$("#ClassYear").val(),名称:$("#ClassName").val()});
		$.ajax({
			url:'http://localhost:3050/api/班级/'+sessionStorage.getItem('Department_Id'),
			cache:false,
			type:'POST',
			contentType: 'application/json; charset=utf-8',
			data:json,
			statusCode:{
				204: function(data){
					$.mobile.changePage('#classListPage',{reloadPage : false });                
				}                          
			}
		});
	}

	//添加一个课程
	function addCourse(){
		var temp;
		if($("#courseType").val()==1)
			temp="必修课";
		else
			temp="公选课";
		//alert(temp);
		if(flagAddCourse()){//是否满足添加课程的要求
			var json=JSON.stringify({
					Id:sessionStorage.getItem('curent_C'),
					周次:$("#week").val(),
					节次:document.getElementById("jieCi-c").innerHTML,
					地点:$("#address").val(),
					课程名:$("#courseName").val(),
					课程类别:temp,
					学期:'1',
					班级Id:localStorage.getItem('class_Id'),
					教师Id:$('#teacher').val()
			});
			if(sessionStorage.getItem('flag_C')==1){	//添加
				//alert(json);
				$.ajax({
					url:'http://localhost:3050/api/课程/添加课程/'+$("#courseType").val()+'/'+localStorage.getItem("loginId"),
					cache:false,
					type:'POST',
					contentType: 'application/json; charset=utf-8',
					data:json,
					statusCode:{
						204: function(data){
							alert('添加成功！');    
							$("#courseName").val("");	//课程名
							$("#address").val("");		//地点
							$("#week").val("");			//周次
							document.getElementById("jieCi-c").innerHTML="NULL";//节次
							$("#courseType").val("");	//课程类别
							$.mobile.changePage('#NewCourse',{reloadPage : false });               
							
						}                          
					}
				});
			}else{	//修改
				$.ajax({
					url:'http://localhost:3050/api/课程/修改课程/'+$("#courseType").val()+'/'+localStorage.getItem("loginId"),
					cache:false,
					type:'POST',
					contentType: 'application/json; charset=utf-8',
					data:json,
					statusCode:{
						204: function(data){
							alert('修改成功！');    
							$.mobile.changePage('#CourseTable',{reloadPage : false });               
							
						}                          
					}
				});
			}
		}else{
			alert("内容不能为空！");
		}
	}

	//是否满足添加课程的要求
	function flagAddCourse()
	{
		//alert($('#teacher').val());
		if($("#week").val()!="" && document.getElementById("jieCi-c").innerHTML!="" && $("#address").val()!="" && $("#courseName").val()!=""  && $('#teacher').val()!=-1 &&  $('#courseType').val()!=-1)
			return true;
		else
			return false;
	}

	//添加课程页重置
	function breakCourse()
	{
		$("#courseName").val("");	//课程名
		$("#address").val("");		//地点
		$("#week").val("");			//周次
		document.getElementById("jieCi-c").innerHTML="NULL";//节次
		$("#courseType").val(-1);//课程类别
		$('#teacher').val(-1);	//教师

	}

	//添加修改课程处理 1:添加  其他:修改
	function abCourseHandle(value)
	{
		if(value==1){
			sessionStorage.setItem('flag_C',1);
			breakCourse();	//清空内容
		}
		else{
			sessionStorage.setItem('flag_C',2);
			modifyCoursePage();		//加载相关内容
		}
		
	}

	//修改课程页面
	function modifyCoursePage()
	{
		$.ajax({
			url:'http://localhost:3050/api/课程/'+sessionStorage.getItem('curent_C')+'/课程',
			type: 'GET',
			dataType:'json',
			jsonp:'callback',
			jsonpCallback:'?',
			timeout:1000,
			async:false,
			success:function(json){
				//alert(json);
				$("#courseName").val(json.课程名);
				$("#address").val(json.地点);
				document.getElementById("jieCi-c").innerHTML=json.节次;
				$("#week").val(json.周次);
				//$('#teacher').val("-1");	//教师
				if(json.课程类别=="必修课")
					 document.getElementById("courseType")[0].selected =true;
				else
					 document.getElementById("courseType")[1].selected =true;
				
			},
			error:function(request,error){
				alert('加载错误：'+error);
			}
		});
	}

	//载入课表
	function loadCourses(curentWeek)
	{
		$.ajax({
                url:'http://localhost:3050/api/班级/'+localStorage.getItem('class_Id')+'/课表',
                type:'GET',
                dataType:'json',
                jsonp:'callback',
                jsonpCallback:'?',
                timeout:1000,
                async:false,
                success:function(json){
					$('#coursesTable tr:gt(0)').remove();	//清空原有
					createTable();	//创建表格
					addTable(json,curentWeek,0);	//添加数据
					
                },
                error:function(request,error){
                    alert('加载错误:'+error);
                }
            });
		//alert(localStorage.getItem('loginId'));
		$.ajax({
                url:'http://localhost:3050/api/用户/'+localStorage.getItem('loginId')+'/课表',
                type:'GET',
                dataType:'json',
                jsonp:'callback',
                jsonpCallback:'?',
                timeout:1000,
                async:false,
                success:function(json){
					if(json!=""){
						//alert(json);
						addTable(json,curentWeek,1);//添加数据
					}
					
                },
                error:function(request,error){
                    alert('加载错误:'+error);
                }
            });
		
	}

	///创建表格 
	function createTable()
	{
		var w=7; //周数
		var p=14; //节数
		var tb=document.createElement("tbody");	//创建tbody
		//document.getElementById('coursesTable').firstChild.removeNode(true);
		for(var period=1;period<=p;period++){
			var tr=document.createElement("tr");	//创建tr标签
			for(var week=0;week<=w;week++){
				var td=document.createElement("td");	//创建td标签
				if(week==0){	//判断是否为节次列
					td.innerHTML=period;		//将当前Td显示的内容设为 节次序号
					td.style.backgroundColor=(period%2==0?"#798299" : "#6b758d");
				}else{
					td.style.backgroundColor=(period%2==0?"#f6f7fa" : "white");
				}
				
				tr.appendChild(td);		//将td标签加入tr
			}
			tb.appendChild(tr);		//将tr标签加入tb
		}
		document.getElementById('coursesTable').appendChild(tb);	//将tb标签加入表格
		//alert(document.getElementById('coursesTable').rows[0].cells[0].innerHTML);
		
	}

	///将取回的课程填入表格
	function addTable(json,curentWeek,flagColor)
	{
		var tdColor=new Array('#6699FF','#9932CC','#F4A460','#FA8072','#F0E68C','#FFD700','#8A2BE2','#4169E1','#ADD8E6');
		var ct=document.getElementById('coursesTable');
		var colorId=0;
		///I:id  V:value  c:课程  p:节次
		$.each(json,function(cI,cV){        //例：
					if(weekRange(cV.周次,curentWeek)){//此时cV对象=  1[1-2;3],2[1-4;5]
						
					var p=cV.节次.split(',');       //此时p数组=   1[1-2;3],2[1-4;5]
					for(var pI in p){
						var pV=p[pI];               
						pV=pV.replace(']','');      //此时pV=  1[1-2;3
						var w=pV.split('[');        //此时w数组=  1,1-2;3
						if(w.length>1)				//假如x=1 即确定为第一周
						{
							var wV=w[1].split(';');     //此时wV数组=   1-2,3
							for(var u in wV){
								var y=[];
								var x=w[0];
								var k=wV[u].split('-');          //此时k数组=  1,2
								//alert(k);
								if(k.length>1){
									for(var j=parseInt(k[0])+1;j<=k[1];j++){
										ct.rows[k[0]].cells[x].rowSpan=ct.rows[k[0]].cells[x].rowSpan+1;
										ct.rows[j].deleteCell(x);
									}
								}
								ct.rows[k[0]].cells[x].innerHTML='<button class="btnL" onClick="jumpHandle((this).value);" value='+cV.Id+'>'+cV.课程名+'['+cV.地点+']'+'</button>';   //根据周及节次将课程加入到指定位置
								ct.rows[k[0]].cells[x].style.backgroundColor=tdColor[colorId]
								ct.rows[k[0]].cells[x].style.color="white";
							}
						}
					}
					
					colorId++;
				}
		});	
	}
	

	//课程详情处理
	function jumpHandle(id)
	{
		
		sessionStorage.setItem('curent_C',id);
		//alert(sessionStorage.getItem('curent_C'));
		$.mobile.changePage('#CourseInfo',{reloadPage : false});
	}

	

	//节次添加
	function addJieCi()
	{
		var result=document.getElementById("jieCi-c");  //获取页面元素
		if(result.innerHTML=="NULL")	//判断是否已有数据，为首次添加做准备
			result.innerHTML="";
		if($('#jieCi-s').val()==$('#jieCi-e').val())
			result.innerHTML=result.innerHTML+$('#jieCi-z').val()+'['+$('#jieCi-e').val()+'],';
		else
			result.innerHTML=result.innerHTML+$('#jieCi-z').val()+'['+$('#jieCi-s').val()+'-'+$('#jieCi-e').val()+'],';
		
	}

	//节次撤销
	function breakJieCi()
	{
		var temp=document.getElementById("jieCi-c").innerHTML;  //获取页面元素
		var key=temp.lastIndexOf('],',temp.length-3);
		//alert(key);
		if(temp!="NULL" && temp!="")
		{
			if(key==-1)
			{
				document.getElementById("jieCi-c").innerHTML="NULL";
			}
			else
				document.getElementById("jieCi-c").innerHTML=temp.substring(0,key+2);
		}
	}
	
	//周次被改变
	function changeCurrentWeek(i)
	{
		$('#coursesTable tr:gt(0)').remove();
		loadCourses(i);
	}

	//周次范围
	function weekRange(aWeek,bWeek)
	{
		if(bWeek==-1)
			return true;
		var temp=aWeek.split('-');
		if(temp.length>1){
			//alert("start:"+temp[0]);
			//alert("end:"+temp[1]);
			//alert("curent:"+bWeek);
			if(temp[0]<=parseInt(bWeek) && temp[1]>=parseInt(bWeek)){
				//alert("true");
				return true;
			}
			else {
				//alert("false");
				return false;
			}
		}else{
			alert(temp[0]);
			if(temp[0]==parseInt(bWeek))
				return true;
			else 
				return false;
		}
		
	}

	//删除当前课程
	function delCurentCourse()
	{
		if(confirm("确认删除？")){
			$.ajax({
				url:'http://localhost:3050/api/课程/'+sessionStorage.getItem('curent_C'),
				cache:false,
				type:'DELETE',
				contentType:'application/json;charset=utf-8',
				statusCode:{
					204:function(data){
						$.mobile.changePage('#CourseTable',{reloadPage : false});
					}
				}
			});
		}
	}

	//添加系部
	function addDepartment()
	{
		if($("#departmentName").val()!="")
		{
			var json=JSON.stringify({系名:$("#departmentName").val()});
			$.ajax({
				url:'http://localhost:3050/api/系部/'+sessionStorage.getItem('Collega_Id'),
				cache:false,
				type:'Post',
				contentType: 'application/json; charset=utf-8',
				data:json,
				statusCode:{
					204: function(data){
						
						alert("添加成功！"); 
						
						$.mobile.changePage('#CollegaList',{reloadPage : false})
					}                          
				}
			});
		}else{
			alert("内容不能为空！");
		}
	}

	//修改用户昵称
	function modifyUserName()
	{
		var temp=$('#newUserName_text').val();
		if(temp!="")
		{
			 
		}else{
			alert("内容不能为空");
		}
	}
	
    </script>
</head>
<body>
	<!-- 登录页-->
    <div id="LoginPage" data-role="page" data-position="fixed" style="background:url(image/Login-bg.png) 50% 0 no-repeat;background-size:cover">
        <div data-role="header" data-position="fixed" data-fullscreen="false">
            <h1>用户登录</h1>
        </div>
        <div data-role="content" >
            <form >
				<div align="center">
					<img src="image/Logo.png" width=95 />
				</div>
                <div  style="margin-top:20px;opacity:0.7;">
                    <input type="text"  id="tloginId" placeholder="用户名" />
                    <input type="password" id="tloginPwd" placeholder="密码" />

                </div>
				
				<div style="margin-top:21px;margin-right:5px;opacity:0.75;" align="right">
						<a style="color:white; font-size:12px;" >忘记密码？</a>
					</div>
				<div style="margin-top:20px;"  >
                        <button   type="button"data-theme="d"  onClick="login($('#tloginId'),$('#tloginPwd')); "><a style="font-size:20px;">Login</a></button>
                </div>
				<div style="margin-top:20px;" >
						 <a href="#RegisterPage" style="background:#DC143C;color:white" data-transition="flip" data-role="button"  data-theme="d"  ">Sign Up</a>
				</div>
				
            </form>
         </div>
		
	</div>
	<!-- 注册页-->
    <div id="RegisterPage" data-role="page" style="background:url(image/Login-bg.png) 50% 0 no-repeat;background-size:cover">
		<div data-role="header" >
			<h1>注册用户</h1>
		</div>
		<div data-role="content">
			<h1 style="color:white">快速注册</h1>
            <form>
                <div   style="margin-top:10px;">
					<input type="text" id="tPhone" placeholder="手机号码" />
                    <input  type="password" id="tregPwd" placeholder="密码" />
					<div style="margin-top:20px;">
                        <fieldset class="ui-grid-a">
                            <div class="ui-block-a">
                                <a  href="#LoginPage" data-icon="arrow-l" data-role="button" data-theme="b"  data-transition="flip">返回</a>
                            </div>
							 <div class="ui-block-b">
                                <button type="button" data-icon="check" data-theme="a" onClick="handles()">注册</button>
                            </div>
                        </fieldset>
                    </div>
                </div>
            </form>
        </div>
    </div>
	<!-- 学院列表-->
    <div id="CollegaList" data-role="page" >
		
        <div data-role="header"  data-fullscreen="true">
           <h1>选择学校</h1>
            
        </div>
        <div data-role="content" id="CollegaListDiv" >
			<div data-role="navbar">
			  <ul>
				<li><a onClick="history.go(0)"  data-role="button" data-icon="refresh" data-theme="c"  >刷新</a></li>
				<li><a href="#" data-role="button" data-icon="alert" data-theme="c" class="ui-btn-right" onClick=" $.mobile.changePage('#CollegaDetail');">学院不存在？</a></li>
			  </ul>
			</div>
            <ul  data-role="listview" data-inset="true"  id="学院-list">   
				
            </ul>
        </div>
    </div>

	<!-- 学院详情-->
    <div id="CollegaDetail" data-role="page" data-title="学院信息">
        <header data-role="header">
            <h1>学院详情</h1>
        </header>
        <div data-role="content">
			<div data-role="navbar" id="GuideCollega">
			  <ul>
				<li><a href="#" data-role="button" data-icon="delete" data-theme="c"  onClick="doDelete();">删除当前学院</a></li>
				<li><a href="#DepartmentPanel"   data-role="button" data-icon="arrow-r" data-theme="c">选择系部</a></li>
			  </ul>
			</div>
            <form>
                <div data-role="fieldcontain" >
                    学院名称：<input type="text" id="collegaName" /><br/>
                    学院地址：<input type="text" id="collegaAddress" />
                    <div style="margin-top:20px;">
                        <fieldset class="ui-grid-a">
                            <div class="ui-block-a">
                                <button type="button" data-icon="back" data-theme="b" onClick=" $.mobile.changePage('#CollegaList',{reloadPage : false});">返回</button>
                            </div>
                            <div class="ui-block-b">
                                <button type="button" data-icon="check" data-theme="a" onclick="doSubmit();">提交</button>
                            </div>
                        </fieldset>
                    </div>
                        
                </div>
            </form>
        </div>

		<!--系部面板-->
		 <div data-role="panel"  data-swipe-close="true" data-dismissible="true"  data-position="right" id="DepartmentPanel" data-display="push "> 
			<h2>请选择系部</h2>
			<div data-role="content">
				<a data-role="button"  data-icon="alert" href="#NewDepartment" data-rel="popup"   data-position-to="window">系部不存在?</a>
				<ul data-role="listview"  data-inset="true"  id="系部-list">
					
				</ul>
			</div>
			<!-- 新建系部-->
			<div data-role="popup" id="NewDepartment" class="ui-content" data-title="新建系部">
				<header>新建系部：</header><input type="text" id="departmentName" /><button data-icon="check" onClick="addDepartment();">OK</button>
			</div>
		</div> 

    </div>

	<!-- 班级列表界 -->
	 <div id="classListPage" data-role="page" >
        <div data-role="header"  data-fullscreen="true">
           <h1>选择班级</h1>
        </div>
        <div data-role="content" >
			<div data-role="navbar">
			  <ul>
				<li>
					<a href="#collegeList" data-role="button" data-icon="back" data-theme="c"   onClick=" $.mobile.changePage('#CollegaDetail',{reloadPage : false});">返回</a>
				</li>
				<li>
					<a href="#clazzDetail" data-role="button" data-icon="plus" data-theme="c"  onClick=" $.mobile.changePage('#NewClass',{reloadPage : false});">班级不存在？</a>
				</li>
			  </ul>
			</div>
            <ul  data-role="listview" data-inset="true"  id="班级-list">   
				
            </ul>
        </div>
    </div>

	<!-- 新建班级-->
    <div id="NewClass" data-role="page" data-title="新建班级">
        <header data-role="header">
            <h1>新班级</h1>
        </header>
        <div data-role="content">
            <form>
                <div data-role="fieldcontain">
                    班级名称：<input type="text" id="ClassName" /><br/><br/>
                    入学年份：<input type="text" id="ClassYear" /><br/><br/>
                    <div style="margin-top:20px;">
                        <fieldset class="ui-grid-a">
                            <div class="ui-block-a">
                                <button type="button" data-theme="b" onClick=" $.mobile.changePage('#classListPage',{reloadPage : false});">关闭</button>
                            </div>
                            <div class="ui-block-b">
                                <button type="button"  data-theme="a" onclick="addClass();">提交</button>
                            </div>
                        </fieldset>
                    </div>
                        
                </div>
            </form>
        </div>
    </div>

	<!-- 课程列表 -->
	<div id="CourseList" data-role="page">
		<div data-role="header" >
			<h1>课程列表</h1>
			<a data-role="button" data-icon="home" data-theme="c" href="#LoginPage" >首页</a>
			<a data-role="button" data-icon="plus" data-theme="c" href="#NewCourse" >添加课程</a>
		</div>
		<div data-role="content">
			<ul data-role="listview" data-inset="true" data-filter="true" id="courseList"></ul>
		</div>
	</div>

	<!--新课程 -->
	<div id="NewCourse" data-role="page">
		<div data-role="header" >
			<h1>添加课程</h1>
			<a data-role="button" data-icon="back" data-theme="a" href="#CourseTable"  class="ui-btn-right">返回</a>
		</div>
		<div data-role="content">
			<form>
				<div >
					<div >
						课程名：<input id="courseName" type="text"  />
						任课教师：<select name="day" id="teacher">
								  </select>
						地点：	<input id="address" type="text" />
						周次：	<input id="week" type="text" placeholder="例如：1-10...." />
						节次：	<div>
								  <fieldset data-role="collapsible" >
									<legend ><a id="jieCi-c" >NULL</a></legend>
									 <div  >
										<select id="jieCi-z"  >
											<option value="1">1</option>
											<option value="2">2</option>
											<option value="3">3</option>
											<option value="4">4</option>
											<option value="5">5</option>
											<option value="6">6</option>
											<option value="7">7</option>
										</select>
									</div>
									<div  data-role="rangeslider"  >
										 <input type="range" name="price-min" id="jieCi-s" value="1" min="1" max="13">
										 <input type="range" name="price-max" id="jieCi-e" value="2" min="1" max="13">
									</div>
									 <div>
										<a data-role="button" data-theme="c" data-inline="true" onClick="document.getElementById('jieCi-c').innerHTML='NULL'"  >清空</a>
										<a data-role="button" data-theme="c" data-inline="true" onClick="breakJieCi();" >撤消</a>
										<a data-role="button" data-theme="c" data-inline="true" onClick="addJieCi();" >追加</a>
										
									</div>
								  </fieldset>
								 
								</div>
						课程类别：	<div  >
										<select id="courseType"  >
											<option value="1">必修课</option>
											<option value="2">公选课</option>
										</select>
									</div>
									
					</div>
					<div style="margin-top:20px;">
                        <fieldset class="ui-grid-a">
                            <div class="ui-block-a">
                                <a href="#" data-role="button" data-icon="back" data-theme="b" onClick="breakCourse();">重置</a>
                            </div>
                            <div class="ui-block-b">
                                <a href="#" data-role="button"  data-icon="check" data-theme="a" onclick="addCourse();">确定</a>
                            </div>
                        </fieldset>
                    </div>
				</div>
			</form>
		</div>
	</div>

	<!--课程课表-->
	<div id="CourseTable" data-role="page"  style="padding:0px">
		<div data-role="header" >
			<!--周次显示-->
			<div  style="width:150px;margin-left:auto; margin-right:auto;"  >
				<select id="currentWeek"   onchange="changeCurrentWeek(this.value)"></select>
			</div>
			<a data-role="button" id="courseTable_name" data-icon="info"  class="ui-btn-left" data-theme="a" style="width:50px;height:20px;text-overflow:ellipsis;overflow:hidden;padding-top:10px" href="#UserInfo"  data-transition="flow"></a>
			<a data-role="button" data-icon="plus"  class="ui-btn-right" data-theme="a" href="#NewCourse" onClick="abCourseHandle(1);"  data-transition="flow">添加</a>
		</div>
		<div data-role="content"  style="background:#3f4258;padding:0px;">
			<!--课表显示-->
			<table style="color:white;width:100%;table-layout:fixed;text-align:center;"   cellspacing="0"     id="coursesTable"   class="ui-responsive">
				<thead  style="background:#798299">
					<th>节</th>
					<th>一</th>
					<th>二</th>
					<th>三</th>
					<th>四</th>
					<th>五</th>
					<th>六</th>
					<th>日</th>
				</thead>
				<tbody>
					
				</tbody>
			</table>
		</div>
		<!-- 个人信息-->
		<div id="UserInfo" data-role="panel" data-title="个人信息" data-swipe-close="true" data-dismissible="true"  data-position="left" data-display="push" data-theme="c" style="background:#ecedf0">
			<div data-role="header"><h1>个人信息</h1></div>
			<div data-role="content" style="font-size:17px;">
				<label id="user_nc"></label><a href="#NewUserName" data-rel="popup"   data-position-to="window">  修改</a><br/>
				<hr/>
				<label id="user_xy"></label><br/>
				<hr/>
				<label id="user_xb"></label><br/>
				<hr/>
				<label id="user_bj"></label><br/>
				<hr/>
				<button onClick="$.mobile.changePage('#CollegaList',{reloadPage : false });">设置向导</button>
				<hr/>
				<button onCLick="$.mobile.changePage('#LoginPage',{reloadPage : false });">注销用户</button>
			</div>

		</div>
		<!-- 修改昵称-->
		<div data-role="popup" id="NewUserName" class="ui-content" data-title="新建系部">
			<header>新昵称：</header><input type="text" id="newUserName_text" /><button data-icon="check" onClick="modifyUserName();">OK</button>
		</div>
	</div>
	
	<!--课程详情-->

	<div id="CourseInfo" data-role="page" data-theme="b" style="background:white">
		<div data-role="header">
			<h1>课程详情</h1>
			<a class="ui-btn-left" href="#CourseTable" data-icon="back">返回</a>
			<a href="#myPopup" class="ui-btn-right" data-rel="popup"   data-position-to="window">?</a>
		</div>
		<div  align="center" data-role="content" class="ui-content" >
			<h1  id="CourseInfo_kcm"></h1>
			<div style="margin-left:15px;font-size:20px;" data-role="fieldcontain" align="left">
				<label id="CourseInfo_dd"></label> <br/><hr/>
				<label id="CourseInfo_sj">时间： </label><br/><hr/>
				<label id="CourseInfo_jc"></label><br/><hr/>
				<label id="CourseInfo_zc"></label><br/><hr/>
				<label id="CourseInfo_js"></label><br/><hr/>
				<label id="CourseInfo_kclx"></label><br/><hr/>
			</div>
		</div>

		<div data-role="popup" id="myPopup" class="ui-content">
			<p>相关操作</p>
			<button data-icon="delete" data-theme="a" onClick="delCurentCourse();">删除当前课程？</button>
			<button  data-theme="b" onClick="$.mobile.changePage('#NewCourse',{reloadPage : false }); abCourseHandle(2);" data-icon="info">信息不对?</button>
		</div>
	</div>
</body>
</html>